@isTest

Private class iFulfillCloneVersionWDControllerTest{


    static testMethod void test_WorkflowTest()

    {
            //Workflow_definition__c wd1 = new Workflow_definition__c();
             Workflow_Definition__c WD = new Workflow_Definition__c();
            //WD.name = 'WD';
             WD.Status__c = 'Active';
             WD.Workflow_Name__c = 'WD';
             WD.Version__c = 1;
             insert WD;

            PageReference pageRef = Page.iFulfillWDCreateVersionPage;
            Test.setCurrentPage(pageRef);
        
            ApexPages.StandardController ctrl = new ApexPages.StandardController(WD);
            iFulfillCloneVersionWDController controller = null;
            Assignment_Group_Name__c AG = new Assignment_Group_Name__c();
        
            AG.name = 'AG1';
            AG.Function__c = 'Advertiser Approval';
            AG.Type__c = 'Fulfillment';
            AG.Description__c = 'Description';
            AG.Round_Robin__c = true;
            insert AG;
                        
            Workflow_Activities__c WA = new Workflow_Activities__c();
            WA.name = 'WA1';
            insert WA;
                                              
            Stage_Definition__c StD = new Stage_Definition__c();
            StD.name = 'East';
            StD.Stage_Description__c = 'Desc';
            StD.Sequence__c = 79;
            StD.Status__c = 'Active';
            insert StD;
            
            Stage_Definition__c StD1 = new Stage_Definition__c();
            StD1.name = 'Advertiser Approval';
            StD1.Stage_Description__c = 'Desc';
            StD1.Sequence__c = 63;
            StD1.Status__c = 'Active';
            insert StD1;
            
            Workflow_Stage__c WFS = new Workflow_Stage__c();
            WFS.name = 'WFS';
            WFS.Stage__c = StD.id;
            WFS.Sequence__c = 1;
            WFS.Workflow_Code__c = WD.id;
            insert WFS;
            
            
            Workflow_Stage__c WFS1 = new Workflow_Stage__c();
            WFS1.name = 'WFS1';
            WFS1.Stage__c = StD1.id;
            WFS1.Sequence__c = 2;
            WFS1.Workflow_Code__c = WD.id;
            insert WFS1;

            
            WF_Assignment_Group__c WAG = new WF_Assignment_Group__c();
            WF_Assignment_Group__c WAG2 = new WF_Assignment_Group__c();

            WAG.Workflow_Function__c = WFS.id;
            WAG.AG_Definition__c = AG.id;
            
            WAG2.Workflow_Function__c = WFS1.id;
            WAG2.AG_Definition__c = AG.id;
            
            insert WAG;
            insert WAG2;

            
            Step_definition__c SD = new Step_definition__c();
            SD.name = 'SD1';
            SD.Stage__c = StD.id;
            SD.Step_Sequence__c = 1;
            SD.Target_Days__c = 4;
            SD.Dashboard_Function__c = 'Design';
            SD.status__c='Active';
            insert SD;
            
            Step_definition__c SD12 = new Step_definition__c();
            SD12.name = 'SD2';
            SD12.Stage__c = StD.id;
            SD12.Step_Sequence__c = 2;
            SD12.Target_Days__c = 4;
            SD12.Dashboard_Function__c = 'Verification';
            SD12.status__c='Active';
            insert SD12;

            
            Wokflow_Steps__c WST = new Wokflow_Steps__c();
            WST.name = 'WST';
            WST.Wokflow_Stage_Name__c = WFS.id;
            WST.Required__c = true;
            WST.Step__c= SD.id;
            WST.Target_Days__c= 11;
            insert WST;
            
            Wokflow_Steps__c WST1 = new Wokflow_Steps__c();
            WST1.name = 'WST 1';
            WST1.Wokflow_Stage_Name__c = WFS.id;
            WST1.Required__c = true;
            WST1.Step__c= SD12.id;
            WST1.Target_Days__c= 5;
            insert WST1;


            //Assignment_Group_Name__c AG = new Assignment_Group_Name__c(name='SG1',Description__c='Desc',);
            
            Activities_Definition__c APD = new Activities_Definition__c();
            APD.name = 'Advertiser Approval';
            APD.Required__c = True;
            APD.Status__c = 'Active';
            APD.Step__c = SD.id;
            insert APD;
            controller = new iFulfillCloneVersionWDController(ctrl);
           

           controller.selectStages();
           controller.selectedSteps();        
           controller.saveGroup();
           
           if(controller.Stages != null && controller.Stages.size() > 0 )
           {
           
           controller.Stages[0].selectbox = true;  
            StD.sequence__c = 1;     
            controller.Stages[0].SD = StD;    
            }
           if( controller.wrapOut != null &&  controller.wrapOut.size()>0)
           { 
           controller.wrapOut[0].Step.selbox=true;
           controller.wrapOut[0].Step.defaultAG=AG.id;        
           controller.wrapOut[0].Step.StepDef.step_sequence__C= 1;
           controller.wrapOut[0].Act[0].slctbox =true;    
           }
           controller.saveUpdatedWFDefn();
           controller.saveFunctions();
    
    }
}